﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoccerSimulator5000
{
    public class Standings
    {
        public List<Team> standings { get; set; }

        public Standings()
        {

        }

        public void Init()
        {
            standings = new List<Team>();
            for (int i = 0; i < 12; i++)
            {
                Team temp = Game.teamList[i];
                standings.Add(temp);
            }
        }

        public void SortStandings()
        {
            standings.Sort();
            for (int i = 0; i < standings.Count; i++)
            {
                standings[i].standingsData.position = i + 1;
            }
        }
        public void Draw( System.Drawing.Graphics g, int x, int y )
        {
            System.Drawing.Font theFont = new System.Drawing.Font("Courier New", 15);
            string header = String.Format("{0,-29}{1,3}|{2,3}|{3,3}|{4,3}|{5,3}|{6,3}|{7,3}|{8,3}",
                                    "Team", "GP", "W ", "D ", "L ", "F ", "A ", "DIF", "PO");

            foreach (var Team in standings)
            {
                Team.standingsData.UpdateData();
            }
            

            int color = 0;

            g.FillRectangle(System.Drawing.Brushes.Beige, x, y, 750, 20);
            g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Brushes.Black), x, y, 750, 20);
            g.DrawString(header, theFont, System.Drawing.Brushes.Black, new System.Drawing.PointF(x+2, y+1));
            y = y + 20;

            SortStandings();

            foreach (var Team in standings)
            {
                object[] arg = { Team.standingsData.position, Team.name, Team.standingsData.gamesPlayed, Team.standingsData.gamesWon, Team.standingsData.gamesDrawn, Team.standingsData.gamesLost, Team.standingsData.goalsFor, Team.standingsData.goalsAgainst, Team.standingsData.goalsDiff, Team.standingsData.points };
                string team = String.Format("{0,-3}{1,-26}{2,3:D}|{3,3:D}|{4,3:D}|{5,3:D}|{6,3:D}|{7,3:D}|{8,3:D}|{9,3:D}", arg);
                if( color == 0 )
                {
                    g.FillRectangle(System.Drawing.Brushes.Aquamarine, x, y, 750, 40);
                    g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Brushes.Black), x, y, 750, 40);
                    color++;
                }
                else
                {
                    g.FillRectangle(System.Drawing.Brushes.AntiqueWhite, x, y, 750, 40);
                    g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Brushes.Black), x, y, 750, 40 );
                    color = 0;
                }
                g.DrawString( team, theFont, System.Drawing.Brushes.Black, new System.Drawing.PointF(x+1, y+10));

                y = y + 40;
            }
        }
    }
}
